package com.arofoxmsn.repository;

import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import com.arofoxmsn.model.User;
import com.arofoxmsn.model.comunication.MobilePhone;
import com.arofoxmsn.model.location.Location;
import com.arofoxmsn.repository.location.LocationTable;

public class UserTable extends BaseTable<User>{
	
	@Override
	protected Class getModelClass() {
		return User.class;
	}
	/**
	 * it retrieves the first row of the table user by a selected phone number.
	 * It is used by
	 * @param mobile
	 * @return an user with the given phone number
	 */
	public User retrieveByPhoneNumber(MobilePhone mobile){
		return retrieveAll(Restrictions.eq("mobile", mobile)).get(0);
	}
	
	/**
	 * this method get All users that have the given locations
	 * @param locationCadidates a list with all locations that candidates could have
	 * @param userId the id of the user who makes the query
	 * @return A list from database of all users that have given locations
	 */
	public List<User> retrieveCandidates(List<Location> locationCadidates, long userId){
		Criterion criterionLocations = Restrictions.in("currentLocation", locationCadidates);
		Criterion criterionMe = Restrictions.not(Restrictions.eq("id", userId));
		return retrieveAll(criterionLocations,criterionMe);
	}
	
}
